package com.linzm.leetcode.primary.exercises1_20230114;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author zimingl
 * @Date 2023/1/12 22:13
 * @Description: 统计一致字符串的数目
 * 给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中，就称这个字符串是 一致字符串 。
 * 请你返回 words 数组中 一致字符串 的数目。
 *
 * 做法： set
 */
public class Demo1_1684 {

    public static void main(String[] args) {
        String allowed = "fstqyienx";
        String[] words = {"n","eeitfns","eqqqsfs","i","feniqis","lhoa","yqyitei","sqtn","kug","z","neqqis"};
        Demo1_1684 Demo1_1684 = new Demo1_1684();
        int num = Demo1_1684.countConsistentStrings(allowed, words);
        System.out.println(num);
    }

    public int countConsistentStrings(String allowed, String[] words) {
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < allowed.length(); i++) {
            set.add(allowed.charAt(i));
        }
        int num = 0;
        for (String word : words) {
            for (int i = 0; i < word.length(); i++) {
                if (!set.contains(word.charAt(i))) {
                    num++;
                    break;
                }
            }
        }
        return words.length - num;
    }
}
